<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="__STATIC__/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="__STATIC__/css/font.css">
    <link rel="stylesheet" href="__STATIC__/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="__STATIC__/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="__STATIC__/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">首页管理</a>
        <a>
          <cite>首页轮播</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">&#xe666;</i></a>
</div>
<div class="x-body" style="margin-top: 4%">
    <div class="layui-col-md4">
        <div style="text-align: center;margin-bottom: 30px;">
            <h2>一号广告位</h2>
            <hr>
        </div>
       <form class="layui-form">
           <div class="layui-form-item">
               <label class="layui-form-label">
                   标题
               </label>
               <div class="layui-input-inline">
                   <input type="text" name="title" required="" lay-verify="required"
                          autocomplete="off" class="layui-input" value="{$data1.title}">
                   <input type="hidden" name="id" value="{$data1.id}">
               </div>
           </div>
           <div class="layui-form-item">
               <label class="layui-form-label">
                   图片
               </label>
               <div class="layui-upload" style="margin-left: 110px;">
                   <button type="button" class="layui-btn" id="test1">图片上传</button>
                   <div class="layui-upload-list">
                       <img class="layui-upload-img" id="demo1" width="100px;" src="{$data1.image}">
                       <input type="hidden" name="image" value="{$data1.image}" id="image1">
                   </div>
               </div>
           </div>
           <div class="layui-form-item">
               <label class="layui-form-label">
                   链接
               </label>
               <div class="layui-input-inline">
                   <input type="text" name="url" required="" lay-verify="required"
                          autocomplete="off" class="layui-input" value="{$data1.url}">
               </div>
           </div>
           <div class="layui-form-item" style="padding-top: 60px;">
               <label  class="layui-form-label">
               </label>
               <button  class="layui-btn" lay-filter="add1" lay-submit="">
                   保存
               </button>
           </div>
       </form>
   </div>
    <div class="layui-col-md4">
        <div style="text-align: center;margin-bottom: 30px;">
            <h2>二号广告位</h2>
            <hr>
        </div>
        <form class="layui-form">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    标题
                </label>
                <div class="layui-input-inline">
                    <input type="text" name="title" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" value="{$data2.title}">
                    <input type="hidden" name="id" value="{$data2.id}">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    图片
                </label>
                <div class="layui-upload" style="margin-left: 110px;">
                    <button type="button" class="layui-btn" id="test2">图片上传</button>
                    <div class="layui-upload-list">
                        <img class="layui-upload-img" id="demo2" width="100px;"src="{$data2.image}">
                        <input type="hidden" name="image" value="{$data2.image}" id="image2">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    链接
                </label>
                <div class="layui-input-inline">
                    <input type="text" name="url" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" value="{$data2.url}">
                </div>
            </div>
            <div class="layui-form-item" style="padding-top: 60px;">
                <label  class="layui-form-label">
                </label>
                <button  class="layui-btn" lay-filter="add2" lay-submit="">
                    保存
                </button>
            </div>
        </form>
    </div>
    <div class="layui-col-md4">
        <div style="text-align: center;margin-bottom: 30px;">
            <h2>三号广告位</h2>
            <hr>
        </div>
        <form class="layui-form">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    标题
                </label>
                <div class="layui-input-inline">
                    <input type="text" name="title" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" value="{$data3.title}">
                    <input type="hidden" name="id" value="{$data3.id}">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    图片
                </label>
                <div class="layui-upload" style="margin-left: 110px;">
                    <button type="button" class="layui-btn" id="test3">图片上传</button>
                    <div class="layui-upload-list">
                        <img class="layui-upload-img" id="demo3" width="100px;" src="{$data3.image}">
                        <input type="hidden" name="image" value="{$data3.image}" id="image3">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    链接
                </label>
                <div class="layui-input-inline">
                    <input type="text" name="url" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" value="{$data3.url}">
                </div>
            </div>
            <div class="layui-form-item" style="padding-top: 60px;">
                <label  class="layui-form-label">
                </label>
                <button  class="layui-btn" lay-filter="add3" lay-submit="">
                    保存
                </button>
            </div>
        </form>
    </div>
</div>
<script>
    layui.use(['form','layer','upload'], function(){
        var form = layui.form
            ,upload = layui.upload
            ,layer = layui.layer;
        upload.render({
            elem: '#test1'
            ,url: '{:url("Goods/goodsImg")}'
            ,before: function(obj){
                obj.preview(function(index, file, result){
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                if(res.code != 1){
                    return layer.msg('上传失败');
                }
                $("#image1").val(res.url);
                form.render();
            }
        });
        form.on('submit(add1)', function(data){
            console.log(data.field);
            $.post('{:url("Home/homeAdvertisementSave")}',data.field,function (res) {
                if (res.code == 1){
                    layer.msg(res.msg, {icon: 6,time:1000});
                }else {
                    layer.msg(res.msg, {icon: 5,time:1500});
                }
            });
            return false;
        });
        upload.render({
            elem: '#test2'
            ,url: '{:url("Goods/goodsImg")}'
            ,before: function(obj){
                obj.preview(function(index, file, result){
                    $('#demo2').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                if(res.code != 1){
                    return layer.msg('上传失败');
                }
                $("#image2").val(res.url);
                form.render();
            }
        });
        form.on('submit(add2)', function(data){
            console.log(data.field);
            $.post('{:url("Home/homeAdvertisementSave")}',data.field,function (res) {
                if (res.code == 1){
                    layer.msg(res.msg, {icon: 6,time:1000});
                }else {
                    layer.msg(res.msg, {icon: 5,time:1500});
                }
            });
            return false;
        });
        upload.render({
            elem: '#test3'
            ,url: '{:url("Goods/goodsImg")}'
            ,before: function(obj){
                obj.preview(function(index, file, result){
                    $('#demo3').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                if(res.code != 1){
                    return layer.msg('上传失败');
                }
                $("#image3").val(res.url);
                form.render();
            }
        });
        form.on('submit(add3)', function(data){
            console.log(data.field);
            $.post('{:url("Home/homeAdvertisementSave")}',data.field,function (res) {
                if (res.code == 1){
                    layer.msg(res.msg, {icon: 6,time:1000});
                }else {
                    layer.msg(res.msg, {icon: 5,time:1500});
                }
            });
            return false;
        });
    });
</script>
</body>

</html>